//
//  PaperAssessmentView.m
//  ZYOnlineSchool
//
//  Created by 毕武侠 on 2017/1/12.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "PaperAssessmentView.h"
#import "PaperAssessmentTitleView.h"
#import "NALLabelsMatrix.h"
#import "PaperAssessmentCollectionView.h"

@interface PaperAssessmentView ()

@property (nonatomic, strong) UILabel *paperName;       // 试卷名称
@property (nonatomic, strong) UILabel *paperTime;       // 交卷时间
@property (nonatomic, strong) UILabel *userScore;       // 用户得分

@property (nonatomic, strong) UILabel *paperAllScore;   // 试卷总分
@property (nonatomic, strong) UILabel *paperDidNums;    // 作答人数

@property (nonatomic, strong) UILabel *answerScore;     // 试题得分
@property (nonatomic, strong) UILabel *answerTime;      // 答题时间
@property (nonatomic, strong) UILabel *answerNums;      // 答题量

@property (nonatomic, strong) UILabel *averageScore;    // 平均得分
@property (nonatomic, strong) UILabel *averageTime;     // 平均做题时间
@property (nonatomic, strong) UILabel *beatNums;        // 击败人数

@property (nonatomic, assign) CGFloat dy;
@property (nonatomic, strong) NALLabelsMatrix *mstrixView;  //
@property (nonatomic, strong) PaperAssessmentCollectionView *collectionView;

@end

@implementation PaperAssessmentView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self createView];
    }
    return self;
}

- (void)createView {
    self.paperName = [[UILabel alloc] initWithFrame:CGRectMake(12, 12, SCREEN_WIDTH - 24, 24)];
    self.paperName.textColor = RGB(40, 40, 40);
    self.paperName.text = @"考卷名称：2016年河南公考试卷";
    self.paperName.font = [UIFont systemFontOfSize:15.0f];
    [self addSubview:self.paperName];
    
    self.paperTime = [[UILabel alloc] initWithFrame:CGRectMake(12, self.paperName.bottom, SCREEN_WIDTH - 24, 24)];
    self.paperTime.textColor = RGB(40, 40, 40);
    self.paperTime.text = @"交卷时间：2016.11.12";
    self.paperTime.font = [UIFont systemFontOfSize:15.0f];
    [self addSubview:self.paperTime];
    
    PaperAssessmentTitleView *resultTitle = [[PaperAssessmentTitleView alloc] initWithFrame:CGRectMake(0, self.paperTime.bottom + 8.0f, SCREEN_WIDTH, 42.0f)];
    resultTitle.text = @"考试结果";
    [self addSubview:resultTitle];
    
    UILabel *paperAllScoreTitle = [[UILabel alloc] initWithFrame:CGRectMake(12, resultTitle.bottom + 12.0f, 64, 24)];
    paperAllScoreTitle.text = @"试卷总分";
    paperAllScoreTitle.font = [UIFont systemFontOfSize:14.0f];
    paperAllScoreTitle.textColor = RGB(40, 40, 40);
    [self addSubview:paperAllScoreTitle];
    
    self.paperAllScore = [[UILabel alloc] initWithFrame:CGRectMake(paperAllScoreTitle.right, paperAllScoreTitle.top, SCREEN_WIDTH/2 - paperAllScoreTitle.right, 24)];
    self.paperAllScore.text = @"：100";
    self.paperAllScore.font = [UIFont systemFontOfSize:14.0f];
    self.paperAllScore.textColor = RGB(40, 40, 40);
    [self addSubview:self.paperAllScore];
    
    
    UILabel *answerScoreTitle = [[UILabel alloc] initWithFrame:CGRectMake(12.0, self.paperAllScore.bottom + 4.0f, 64, 20)];
    answerScoreTitle.textColor = [UIColor darkGrayColor];
    answerScoreTitle.text = @"试卷得分";
    answerScoreTitle.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:answerScoreTitle];
    
    self.answerScore = [[UILabel alloc] initWithFrame:CGRectMake(answerScoreTitle.right, answerScoreTitle.top, SCREEN_WIDTH / 2 - answerScoreTitle.right, 20)];
    self.answerScore.textColor = [UIColor darkGrayColor];
    self.answerScore.text = @"：90分";
    self.answerScore.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.answerScore];

    UILabel *answerTimeTitle = [[UILabel alloc] initWithFrame:CGRectMake(12.0, answerScoreTitle.bottom, 64, 20)];
    answerTimeTitle.textColor = [UIColor darkGrayColor];
    answerTimeTitle.text = @"答题时长";
    answerTimeTitle.font = [UIFont systemFontOfSize:15.0f];
    [self addSubview:answerTimeTitle];
    
    self.answerTime = [[UILabel alloc] initWithFrame:CGRectMake(answerTimeTitle.right, answerTimeTitle.top, SCREEN_WIDTH / 2 - answerTimeTitle.right, 20)];
    self.answerTime.textColor = [UIColor darkGrayColor];
    self.answerTime.text = @"：2小时3分钟";
    self.answerTime.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.answerTime];
    
    UILabel *answerNumsTitle = [[UILabel alloc] initWithFrame:CGRectMake(12.0, answerTimeTitle.bottom, 64, 20)];
    answerNumsTitle.textColor = [UIColor darkGrayColor];
    answerNumsTitle.text = @"答题量";
    answerNumsTitle.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:answerNumsTitle];
    
    self.answerNums = [[UILabel alloc] initWithFrame:CGRectMake(answerNumsTitle.right, answerNumsTitle.top, SCREEN_WIDTH / 2 - answerNumsTitle.right, 20)];
    self.answerNums.textColor = [UIColor darkGrayColor];
    self.answerNums.text = @"：90／40道";
    self.answerNums.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.answerNums];
    
    
    UILabel *averageScoreTitle = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+12.0f, self.paperAllScore.bottom + 4.0f, 64, 20)];
    averageScoreTitle.textColor = [UIColor darkGrayColor];
    averageScoreTitle.text = @"平均得分";
    averageScoreTitle.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:averageScoreTitle];
    
    self.averageScore = [[UILabel alloc] initWithFrame:CGRectMake(0, averageScoreTitle.top, SCREEN_WIDTH / 2 - averageScoreTitle.right, 20)];
    self.averageScore.left = averageScoreTitle.right;
    self.averageScore.textColor = [UIColor darkGrayColor];
    self.averageScore.text = @"：90分";
    self.averageScore.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.averageScore];
    
    UILabel *averageTimeTitle = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+12.0f, averageScoreTitle.bottom, 64, 20)];
    averageTimeTitle.textColor = [UIColor darkGrayColor];
    averageTimeTitle.text = @"平均时间";
    averageTimeTitle.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:averageTimeTitle];
    
    self.averageTime = [[UILabel alloc] initWithFrame:CGRectMake(0, averageTimeTitle.top, SCREEN_WIDTH / 2 - averageScoreTitle.right, 20)];
    self.averageTime.left = averageTimeTitle.right;
    self.averageTime.textColor = [UIColor darkGrayColor];
    self.averageTime.text = @"：2小时";
    self.averageTime.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.averageTime];
    
    UILabel *beatNumsTitle = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2+12.0f, averageTimeTitle.bottom, 64, 20)];
    beatNumsTitle.textColor = [UIColor darkGrayColor];
    beatNumsTitle.text = @"击败人数";
    beatNumsTitle.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:beatNumsTitle];
    
    self.beatNums = [[UILabel alloc] initWithFrame:CGRectMake(0, beatNumsTitle.top, SCREEN_WIDTH / 2 - beatNumsTitle.right, 20)];
    self.beatNums.left = beatNumsTitle.right;
    self.beatNums.textColor = [UIColor darkGrayColor];
    self.beatNums.text = @"：100人";
    self.beatNums.font = [UIFont systemFontOfSize:14.0f];
    [self addSubview:self.beatNums];
    
    PaperAssessmentTitleView *dataTitle = [[PaperAssessmentTitleView alloc] initWithFrame:CGRectMake(0, self.beatNums.bottom + 12.0f, SCREEN_WIDTH, 42.0f)];
    dataTitle.text = @"试卷数据";
    [self addSubview:dataTitle];
    
    self.dy = dataTitle.bottom;
}

- (void)createNextView {
    
    self.userScore = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 76, 12, 70, 66)];
    self.userScore.text = @"90";
    self.userScore.font = [UIFont fontWithName:@"CourierNewPSMT" size:50.0f];   //TrebuchetMS
    CGPoint center = self.userScore.center;
    center.x = SCREEN_WIDTH * 0.82;
    self.userScore.center = center;
    
    [self addSubview:self.userScore];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 82, self.userScore.bottom - 16, 76, 30)];
    imageView.image = [UIImage imageNamed:@"FenBottom"];
    center = imageView.center;
    center.x = SCREEN_WIDTH * 0.83;
    imageView.center = center;
    [self addSubview:imageView];
    
//    NSNumber *columnsWidth = [NSNumber numberWithFloat:(SCREEN_WIDTH - 24.0f) / 4.0];
    
//    self.mstrixView = [[NALLabelsMatrix alloc] initWithFrame:CGRectMake(12, self.dy + 12.0, SCREEN_WIDTH - 24.0, 100) andColumnsWidths:@[columnsWidth, columnsWidth, columnsWidth, columnsWidth]];
//    [self.model.paperDatas enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//        [self.mstrixView addRecord:obj];
//    }];
//    [self addSubview:self.mstrixView];
    
    PaperAssessmentTitleView *dataTitle = [[PaperAssessmentTitleView alloc] initWithFrame:CGRectMake(0, self.dy + 12.0, SCREEN_WIDTH, 42.0f)];
    dataTitle.text = @"答题卡";
    [self addSubview:dataTitle];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    self.collectionView = [[PaperAssessmentCollectionView alloc] initWithFrame:CGRectMake(0, dataTitle.bottom + 8.0f, SCREEN_WIDTH, 100) collectionViewLayout:layout];
    self.collectionView.modelClass = @"CapabilityAssessmentCollectionModel";
    self.collectionView.minInteritemSpace = 32.0f;
    self.collectionView.minLineSpace = 16.0f;
    self.collectionView.edgeInsets = UIEdgeInsetsMake(0, 16.0f, 16.0f, 16.0f);
    self.collectionView.sourceData = self.model.model_question;
    [self addSubview:self.collectionView];
    
    self.dy = self.collectionView.bottom + 12.0f;
    self.contentSize = CGSizeMake(SCREEN_WIDTH, self.dy);
}

- (void)setModel:(PaperAssessmentModel *)model {
    _model = model;
    [self createNextView];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
